<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%@ include file="/common/grid/jqGrid.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="">
	<meta http-equiv="description" content="This is my page">

  </head>
  
  <body>
    	<s:form name="frm" id="frm" method="post" action="" namespace="">
    		<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
    			<jsp:param name="menuLink" value="[{'name':'修改问卷'}]"/>
    			<jsp:param name="width" value="50%"/>
    		</jsp:include>
    		<s:hidden name="paper.id" id="paperId"></s:hidden>
    		<table cellspacing="1" cellpadding="3" bgcolor="#CCCCCC" width="100%">
    			<tr bgcolor="#FFFFFF">
    				<td width="20%" class="label" align="right">
    					问卷编号：
    				</td>
    				<td width="30%" align="left">
   						<s:property value="paper.paperCode" />
    				</td>
    				<td width="20%" class="label" align="right">
    					问卷名称：
    				</td>
    				<td width="30%" align="left">
    					<s:textfield name="paper.paperName" id="paperName" cssStyle="width:90%;" maxlength="20"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td class="label" align="right">
    					半开放题行数：
    				</td>
    				<td align="left">
    					<s:textfield name="paper.halfQesRow" id="halfQesRow" cssStyle="width:90%;" maxlength="2"></s:textfield>
    				</td>
    				<td class="label" align="right">
    					全开放题行数：
    				</td>
    				<td align="left">
    					<s:textfield name="paper.fullQesRow" id="fullQesRow" cssStyle="width:90%;" maxlength="2"></s:textfield>
    				</td>
    			</tr>
    			<tr bgcolor="#FFFFFF">
    				<td class="label" align="right">
    					问卷时间：
    				</td>
    				<td align="left">
    					<input type="text" name="paper.paperTime" id="paperTime" class="WDate" style="width:120px;" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="<s:date name='paper.paperTime' format='yyyy-MM-dd' />" />
    				</td>
    				<td align="right">
    					
    				</td>
    				<td align="left">
    				
    				</td>
    			</tr>
    		</table>
    		
    		<table width="100%" cellspacing="0">
    			<tr>
    				<td align="center" valign="bottom" height="30">
    					<input type="button" value="保存" class="btn" onclick="saveThis()" />
    				</td>
    			</tr>
    		</table>
    	</s:form>
    	
    	<s:form name="frm2" id="frm2" method="post" action="" namespace="">
	   		<table cellspacing="1" width="100%" bgcolor="#CCCCCC">
				<tr bgcolor="#FFFFFF">
					<td align="right" width="10%" class="label">
						题目名称：
					</td>
					<td align="left" width="23%">
						<s:textfield id="qesTitle" cssStyle="width:80%" cssClass="search"></s:textfield>
					</td>
					<td align="right" width="77%"></td>
				</tr>
			</table>
	   		<table cellspacing="0" width="100%">
				<tr>
					<td align="left">
	   					<input type="button" value="新增" class="btn" onclick="addQuestion()" />
	   					<input type="button" value="查询" class="btn" onclick="searchThis()" />
	   					<input type="button" value="重置" class="btn" onclick="resetSearch()" />
	   				</td>
	   			</tr>
	   		</table>
	   		<table id="list" cellpadding="3" cellspacing="0"></table>
			<div id="pager" style="text-align:center;"></div>
	   	</s:form>
    	
    
    <script type="text/javascript">
    $(document).ready(function(){
        var cName = new Array('题号','类型', '题目', '答案长度', '个数', '所用码表', '所用组题', '操作');
    	var cModel = [
    					{name:'qesCode', index:'qesCode', width:'12%', align:'center'},
    					{name:'dataValue', index:'dataValue', width:'10%', align:'center'},
                        {name:'qesTitle', index:'qesTitle', width:'24%', align:'center'},
                        {name:'width', index:'width', width:'10%', align:'center'},
                        {name:'quantity', index:'quantity', width:'10%', align:'center'},
                        {name:'codetb', index:'ct.code', width:'10%', align:'center'},
                        {name:'codeLabel', index:'ct2.code', width:'10%', align:'center'},
                        {name:'id', index:'id', width:'14%', align:'center', sortable:false, formatter:option}
                      ];
        
        newJqGrid({
        	id: 'id',
        	gridId: 'list',
        	pagerId: 'pager',
        	url: 'inner/qes/questionListByPage.action?pvo.paperId=' + $('#paperId').val(),
        	head: cName,
        	column: cModel,
        	width: getBodyWidth(),
        	height: 'auto',
        	hasCb: false,
        	title: '问题列表'
        });
        
        $(window).resize(function(){
        	gridAutoWidth('list', 'win');
        });
    });
    
    function saveThis()
    {
    	var paperName = $('#paperName');
    	var halfQesRow = $('#halfQesRow');
    	var fullQesRow = $('#fullQesRow');
    	var paperTime = $('#paperTime');
    	if(!isNotNull(paperName.val()))
    	{
    		showMsg('问卷名称不能为空。', function(){paperName.focus();});
    		return;
    	}
    	if(checkInteger(halfQesRow) == false || parseInt(halfQesRow.val()) <= 0)
    	{
    		showMsg('半开放题行数必须为正整数。', function(){halfQesRow.focus();});
    		return;
    	}
    	if(checkInteger(fullQesRow) == false || parseInt(fullQesRow.val()) <= 0)
    	{
    		showMsg('全开放题行数必须为正整数。', function(){fullQesRow.focus();});
    		return;
    	}
    	if(!isNotNull(paperTime.val()))
    	{
    		showMsg('问卷时间不能为空。', function(){paperTime.focus();});
    		return;
    	}
    	ajaxAction('inner/qes/updatePaper.action', 'post', 'frm', false, function(){
   			showMsg('保存成功。');
    	});
    }
    
    function searchThis()
    {
    	var params = {
    		'pvo.qesTitle':$('#qesTitle').val()
    	};
    	toSearchList('list', params);
    }
    
    function option(cellVal, options, row)
    {
    	var html = '<a href="javascript:updateQuestion(\'' + row['id'] + '\')" >修改</a>';
    	html += ' <a href="javascript:delQuestion(\'' + row['id'] + '\')" >删除</a>';
    	return html;
    }
    
    function addQuestion()
    {
    	var url = realPath + '/inner/qes/toAddQuestion.action?qes.paper.id=' + $('#paperId').val();
    	openWin(url, 750, 710, 'yes', 'yes');
    }
    
    function updateQuestion(id)
    {
    	var url = realPath + '/inner/qes/toUpdateQuestion.action?qes.id=' + id + '&qes.paper.id=' + $('#paperId').val();
    	openWin(url, 750, 710, 'yes', 'yes');
    }
    
    function delQuestion(id)
    {
    	showConfirm('确认删除？', function(v){
    		if(v == true)
    		{
		    	var url = 'inner/qes/delQuestion.action?qes.id=' + id;
		    	ajaxAction(url, 'post', 'frm', false, function(){
		    		searchThis();
		    	});
    		}
    	});
    }
    </script>
  </body>
</html>
